package demo.team.spring3.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import demo.team.spring3.to.Login;

@Controller
public class LoginController {

	@RequestMapping(value="/login.htm", method= RequestMethod.GET)
	public String validateLogin(Model model)
	{
		Login login = new Login();
		model.addAttribute("login", login);
		return "loginMgr";
	}
	
	@RequestMapping(value="/login.htm", method= RequestMethod.POST)
	public String submitLogin(@ModelAttribute("login")Login login, BindingResult result, HttpServletRequest request)
	{
		String username=login.getUserName();
		String password=login.getPassWord();
		System.out.println("User : "+username+" PASS : "+password);
		request.getSession().setAttribute("LOGGED_IN", login);	
		return "interceptedPage";
	}
	
	@RequestMapping(value="/interceptedPage.htm", method= RequestMethod.GET)
	public String validateInterception(Model model)
	{
		System.out.println("INSIDE validateInterception METHOD OF CONTROLLER");
		return "interceptedPage";
	}
	
	@RequestMapping(value="/priviledgedPage.htm", method= RequestMethod.GET)
	public String validateAuthentication(Model model)
	{
		System.out.println("INSIDE validateAuthentication METHOD OF CONTROLLER");
		return "priviledgedPage";
	}
}
